# @Author: 唐奇才
# @Time: 2021/5/4 14:48
# @File: testJson.py
# @Software: PyCharm

import json


def test():
    data1 = {
        "programmers":
            [
                {"firstName": "Brett", "lastName": "McLaughlin", "email": "aaaa"},
                {"firstName": "Jason", "lastName": "Hunter", "email": "bbbb"},
                {"firstName": "Elliotte", "lastName": "Harold", "email": "cccc"}
            ],
        "authors":
            [
                {"firstName": "Isaac", "lastName": "Asimov", "genre": "science fiction"},
                {"firstName": "Tad", "lastName": "Williams", "genre": "fantasy"},
                {"firstName": "Frank", "lastName": "Peretti", "genre": "christian fiction"}
            ]
    }
    print('data1["programmers"][0]:', data1["programmers"][0])
    print('data1["programmers"][0]["firstName"]:', data1["programmers"][0]['firstName'])
    print('data1["authors"][1]["lastName"]:', data1["authors"][1]['lastName'])


def getDataFromJsonFile():
    with open("./testJsonFile.json", "r", encoding="utf-8") as f:
        jd = json.load(f)
    print(f)
    return jd

def saveJsonData():
    with open("saveData.json", "w", encoding="utf-8") as f:
        #         有数据的内容             写入的文件
        json.dump(getDataFromJsonFile(), f, ensure_ascii=False)

def main():
    getDataFromJsonFile()
    # saveJsonData()


if __name__ == '__main__':
    main()
